package com.example.opengl_test00;


public class Vertor3f {
	public float x;
	public float y;
	public float z;
	
	public Vertor3f(float x,float y,float z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public Vertor3f(Vertor3f v) {
		this.x = v.x;
		this.y = v.y;
		this.z = v.z;
	}
	
	// Operator
	public Vertor3f add(Vertor3f v)	{
		return new Vertor3f(this.x + v.x, this.y + v.y, this.z + v.z);
	}
	
	public Vertor3f add(float v)	{
		return new Vertor3f(this.x + v, this.y + v, this.z + v);
	}
	
	public Vertor3f sub(Vertor3f v)	{
		return new Vertor3f(this.x - v.x, this.y - v.y, this.z - v.z);
	}
	
	public Vertor3f multi(float v) {
		return new Vertor3f(this.x * v, this.y * v, this.z * v);
	}

	public Vertor3f cross(Vertor3f v) {
		return new Vertor3f(
				y*v.z - z*v.y, 
				z*v.x - x*v.z, 
				x*v.y - y*v.x);
	}
	
	public float dot(Vertor3f v) {
		return this.x * v.x + this.y * v.y + this.z + v.z; 
	}
	
	public Vertor3f normal() {
		float length = length();
		return multi(1.0f / length);
	}
	
	public float length() {
		return (float)Math.sqrt(x * x + y * y + z * z);
	}
	
	public float[] toArray() {
		return new float[] { x, y, z };
	}
	
	@Override
	public String toString() {
		return "{ " + x + ", " + y + ", " + z + " }";
	}

}
